package com.zp.io;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class DataOutputStreamTest {
	public static void main(String[] args) throws IOException {
		DataOutputStream dos = new DataOutputStream(new BufferedOutputStream
				(new FileOutputStream("D:/lisi/file.txt")));
		
		int a = 2;
		byte b = 4;
		char c = 'z';
		
		dos.writeInt(a);
		dos.writeByte(b);
		dos.writeChar(c);
		
		dos.close();
		
		DataInputStream dis = new DataInputStream(new BufferedInputStream
				(new FileInputStream("D:/lisi/file.txt")));
		
		/**
		 * 写入的顺序必须和输出的顺序一致，因为写入的时候是根据输出文件按顺序读取的，
		 */
		System.out.println(dis.readInt());
		System.out.println(dis.readByte());
		System.out.println(dis.readChar());
		
		dis.close();
	}
}
